package com.qww.exec12;

public class Exec12 {

    public static void main(String[] args) {
        Tank tank1 = new Tank();
        tank1.clean();
        System.gc();
        System.out.println("==============");
        new Tank();
        // 忘记清理数据，也就是忘记调用clean()
        System.gc();
        System.runFinalization();
    }
}

class Tank {
    // 状态 true 表示满的，false表示空的
    boolean isEmpty = true;

    Tank() {
        isEmpty = false;
    }

    void clean() {
        System.out.println("clean up...");
        isEmpty = true;
        System.out.println("status is empty.");
    }

    @Override
    protected void finalize() throws Throwable {
        if (!isEmpty) {
            System.out.println("Error: tank is full! You must clean data by call clean().");
        }
    }
}
